<%@page import="java.io.File"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.FileItemFactory"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	FileItemFactory fif=new DiskFileItemFactory();
	ServletFileUpload upload=new ServletFileUpload(fif);
	
	if(ServletFileUpload.isMultipartContent(request)){
		List<FileItem> list=upload.parseRequest(request);
		for(FileItem fi : list){
			if(fi.isFormField()){
				//普通
				String val=fi.getString("utf-8");
				String name=fi.getFieldName();
				if(name.equals("pname")) out.print("商品名："+val+"<br/>");
				if(name.equals("price")) out.print("价格："+val+"<br/>");
			}else{
				//文件
				String path=application.getRealPath("/test");
				String filename= new File(fi.getName()).getName();
				File f=new File(path+"/"+filename);
				fi.write(f);
				out.print("上传成功："+filename);
			}
		}
	}
%>
